package com.example.wechat.controller;

import com.example.wechat.mapper.GroupMessageRepository;
import com.example.wechat.model.GroupMessage;

import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;

@Controller
public class GroupMessageController {

    private final GroupMessageRepository groupMessageRepository;

    public GroupMessageController(GroupMessageRepository groupMessageRepository) {
        this.groupMessageRepository = groupMessageRepository;
	}

	@MessageMapping("/group.chat.send")
	@SendTo("/topic/group.{groupId}")
	public GroupMessage sendGroupMessage(GroupMessage message) {
		groupMessageRepository.insert(message);
		return message;
	}
}